package com.example.rabbitmq.starter.entity;

import com.example.rabbitmq.starter.util.JpaJsonConverter;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * MQ配置信息实体类
 */
@Data
@Entity
@Table(name = "mq_config_info")
public class MQConfigInfo {

    @Comment("配置ID")
    @Id
    private String id;

    @Comment("业务标识/配置名称")
    @Column(nullable = false, unique = true)
    private String businessName;

    @Comment("描述")
    private String description;

    @Comment("交换机名称")
    @Column(nullable = false)
    private String exchangeName;

    @Comment("交换机类型：direct, topic, fanout, headers")
    @Column(nullable = false)
    private String exchangeType;

    @Comment("是否持久化交换机")
    private boolean exchangeDurable;

    @Comment("队列名称")
    @Column(nullable = false)
    private String queueName;

    @Comment("是否持久化队列")
    private boolean queueDurable = true;

    @Comment("是否自动删除队列")
    private boolean queueAutoDelete = false;

    @Comment("路由键")
    private String routingKey;

    @Comment("队列参数")
    @Convert(converter = JpaJsonConverter.class)
    @Column(columnDefinition = "TEXT")
    private Map<String, Object> queueArguments = new HashMap<>();

    @Comment("交换机参数")
    @Convert(converter = JpaJsonConverter.class)
    @Column(columnDefinition = "TEXT")
    private Map<String, Object> exchangeArguments = new HashMap<>();

    @Comment("最大重试次数")
    private int maxRetryCount;

    @Comment("消息类型")
    @Column(nullable = false, unique = true)
    private String messageType;

    @Comment("失败后置处理类路径")
    private String failureHandlerClass;

    @Comment("状态：启用/禁用")
    private boolean enabled;

    @Comment("备注")
    private String remark;

    @Comment("创建时间")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    @Comment("更新时间")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
}